<!DOCTYPE html>
<html lang="zh-CN">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>网站爬虫</title>
	</head>
	<body>
		<script>
			const url =
				'https://www.chuhai2345.com/wp-content/uploads/2024/10/%E8%BD%AF%E4%BB%B6logo%EF%BC%88%E9%9D%9E%E9%80%8F%E6%98%8E%E8%83%8C%E6%99%AF60%C3%9760%EF%BC%89.png'
			function downloadImage(imgUrl, imgName) {
				const xhr = new XMLHttpRequest()
				xhr.open('GET', imgUrl, true)
				xhr.responseType = 'blob'
				xhr.onload = function () {
					const url = window.URL.createObjectURL(xhr.response)
					const link = document.createElement('a')
					link.href = url
					link.download = imgName // 指定下载文件名
					link.style.display = 'none'
					document.body.appendChild(link)
					link.click() // 模拟点击
					setTimeout(function () {
						window.URL.revokeObjectURL(url)
						document.body.removeChild(link) // 移除链接
					}, 0)
				}
				xhr.send()
			}

			downloadImage(url, 'logo.png')

			function grawl() {
				const siteCardA = document.querySelectorAll('.site-card-a')

				for (let a of siteCardA) {
					const title = a.querySelector('strong').textContent
					const link = a.href
					const imgUrl = a.querySelector('img').src
					console.log(`标题：${title}   链接：${link}   图片：${imgUrl}`)
					// downloadImage(imgUrl, title + '.png')
				}
			}

			grawl()
		</script>
	</body>
</html>
